package yyy.ab.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import yyy.ab.modules.system.entity.SysUserRole;
import yyy.ab.modules.system.entity.dto.SysRoleSmallDto;

import java.util.List;

/**
 * 系统用户角色mapper
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

    /**
     * @param userId 用户id
     * @return
     */
    @Select("SELECT role.id as value,role.code,role.name from sys_user_role userRole join sys_role role on userRole.role_id=role.id where userRole.user_id=#{userId}")
    List<SysRoleSmallDto> findRoleSmallByUserId(Long userId);

    /**
     * @param userId 用户id
     * @return
     */
    @Select("select distinct menu.permission from sys_role_menu roleMenu join sys_role role on roleMenu.role_id=role.id join sys_menu menu on roleMenu.menu_id=menu.id join sys_user_role userRole on userRole.role_id=roleMenu.role_id where userRole.user_id=#{userId} and ifnull(menu.permission,'') != '' order by roleMenu.role_id")
    List<String> findPermissionByUserId(Long userId);
}
